package com.banmoon.datastructure.ArrayBinaryTree;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.Objects;

@Data
@AllArgsConstructor
public class ArrayBinaryTree {

    private Integer[] data;

    public void frontShow() {
        if (Objects.isNull(data) || data.length == 0)
            return;
        frontShow(0);
    }

    /**
     * 前序遍历
     * @param index
     */
    public void frontShow(int index) {
        System.out.println(data[index] + ",");
        int i;
        if ((i = index*2+1) < data.length)
            frontShow(i);
        if ((i = index*2+2) < data.length)
            frontShow(i);
    }
}
